<template>
    <div class="g-icons">
        <swiper :options="swiperOption" v-if="showIcons">
            <!-- slides -->
            <swiper-slide v-for="(page, index) of pages" :key="index">
                <div v-for="item of page" :key="item.id" class="icon-item">
                    <div class="icon-img">
                        <img :src="item.imgUrl" alt="">
                    </div>
                    <p class="icon-desc">{{ item.desc }}</p>
                </div>
            </swiper-slide>
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
        <!-- <ul>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png" alt="">
                </div>
                <p>景点门票</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png" alt="">
                </div>
                <p>一日游</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png" alt="">
                </div>
                <p>杭州必游</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1803/75/eca3ce656c886502.png" alt="">
                </div>
                <p>漂流</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1803/6a/45f595250c73d102.png" alt="">
                </div>
                <p>夏日玩水</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1803/17/99402a22ce4af302.png" alt="">
                </div>
                <p>西湖</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png" alt="">
                </div>
                <p>宋城千古情</p>
            </li>
            <li>
                <div class="icon-img">
                    <img src="http://img1.qunarzz.com/piao/fusion/1804/95/8d02011d149bdb02.png" alt="">
                </div>
                <p>汽车票</p>
            </li>

        </ul> -->
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        // 所有的参数同 swiper 官方 api 参数
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    //   计算函数--分页(如果图片超过8个就分页)
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    },
    showIcons () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
    @import '~styles/variables.styl'
    @import '~styles/mixins.styl'
    .g-icons >>> .swiper-container
        height 0
        padding-bottom 56%
        .swiper-pagination
            position: absolute;
            bottom: 6px;
            padding: 0 6px;
            width: 100%;
            text-align: center;
    .g-icons
        margin-top .1rem
    .icon-item
        position relative
        overflow hidden
        float left
        width 25%
        height 0
        padding-bottom 25%
        // background red
        .icon-img
            position absolute
            top 0
            left 0
            right 0
            bottom .44rem
            box-sizing border-box
            padding .1rem
            // background blue
            img
                display block
                margin 0 auto
                height 100%
        .icon-desc
            position absolute
            bottom 0
            left 0
            right 0
            heihgt .44rem
            line-height .44rem
            text-align center
            color: $textColor
            ellipsis()

</style>
